# Contributor: Michał Polański <michal@polanski.me>
# Maintainer: Michał Polański <michal@polanski.me>
pkgname=kustomize
pkgver=5.3.0
pkgrel=3
pkgdesc="Template-free customization of Kubernetes YAML manifests"
url="https://kustomize.io/"
license="Apache-2.0"
arch="all"
makedepends="go"
subpackages="
	$pkgname-bash-completion
	$pkgname-fish-completion
	$pkgname-zsh-completion
	"
source="https://github.com/kubernetes-sigs/kustomize/archive/kustomize/v$pkgver/kustomize-$pkgver.tar.gz"
builddir="$srcdir/kustomize-kustomize-v$pkgver/kustomize"

export GOCACHE="${GOCACHE:-"$srcdir/go-cache"}"
export GOTMPDIR="${GOTMPDIR:-"$srcdir"}"
export GOMODCACHE="${GOMODCACHE:-"$srcdir/go"}"

build() {
	local builddate="$(date -u "+%Y-%m-%dT%TZ" ${SOURCE_DATE_EPOCH:+-d @$SOURCE_DATE_EPOCH})"

	go build -ldflags="
		-X sigs.k8s.io/kustomize/api/provenance.version=$pkgver
		-X sigs.k8s.io/kustomize/api/provenance.buildDate=$builddate
		"

	./kustomize completion bash > $pkgname.bash
	./kustomize completion fish > $pkgname.fish
	./kustomize completion zsh > $pkgname.zsh
}

check() {
	go test ./...
}

package() {
	install -Dm755 kustomize -t "$pkgdir"/usr/bin/

	install -Dm644 $pkgname.bash "$pkgdir"/usr/share/bash-completion/completions/$pkgname
	install -Dm644 $pkgname.fish "$pkgdir"/usr/share/fish/vendor_completions.d/$pkgname.fish
	install -Dm644 $pkgname.zsh "$pkgdir"/usr/share/zsh/site-functions/_$pkgname
}

sha512sums="
d9c8545c9e2fa0b650e45a2a397c823e8157dc9361293dd0abd8a2f64dc10733dbcb030c7b781215997f741edd196b035616b943f4ad30158ba39b4587f1d9d4  kustomize-5.3.0.tar.gz
"
